package es.uca.gii.csi.Shield.gui;

import java.awt.EventQueue;

import javax.swing.JInternalFrame;

import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.factories.FormFactory;

import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Calendar;

import es.uca.gii.csi.Shield.data.*;

public class IfrAgente extends JInternalFrame {
	

	private Agente _agente = null;
	private JTextField txtNombre;
	private JTextField txtAnosServicio;
	private JTextField txtFechaValidezLicencia;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					IfrAgente frame = new IfrAgente();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public IfrAgente() {
		setClosable(true);
		setRootPaneCheckingEnabled(false);
		setTitle("Agente");
		setBounds(100, 100, 450, 300);
		getContentPane().setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),},
			new RowSpec[] {
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,}));
		
		JLabel lblNombre = new JLabel("Nombre");
		lblNombre.setHorizontalAlignment(SwingConstants.RIGHT);
		getContentPane().add(lblNombre, "2, 4, right, default");
		
		txtNombre = new JTextField();
		getContentPane().add(txtNombre, "4, 4, fill, default");
		txtNombre.setColumns(10);
		
		JLabel lblAnosServicio = new JLabel("Años de Servicio");
		lblAnosServicio.setHorizontalAlignment(SwingConstants.RIGHT);
		getContentPane().add(lblAnosServicio, "2, 6, right, default");
		
		txtAnosServicio = new JTextField();
		getContentPane().add(txtAnosServicio, "4, 6, fill, default");
		txtAnosServicio.setColumns(10);
		
		JLabel lblFechaValidezLicencia = new JLabel("Fecha Validez Licencia");
		lblFechaValidezLicencia.setHorizontalAlignment(SwingConstants.RIGHT);
		getContentPane().add(lblFechaValidezLicencia, "2, 8, right, default");
		
		txtFechaValidezLicencia = new JTextField();
		getContentPane().add(txtFechaValidezLicencia, "4, 8, fill, default");
		txtFechaValidezLicencia.setColumns(10);
		
		JButton butGuardar = new JButton("Guardar");
		butGuardar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(_agente == null)
					_agente = Agente.New(txtNombre.getText(), Integer.parseInt(txtAnosServicio.getText()), 
										Calendar.parseCalendar(txtFechaValidezLicencia.getText());
			}
		});
		getContentPane().add(butGuardar, "2, 14");

	}

}
